package br.com.jk.valealim.cartaovenda;

import br.com.jk.valealim.cartao.Cartao;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;

/**
 *
 * @author camilo
 */
@Entity
@Table(name = CartaoVendaDao.NAME_TABLE, schema = CartaoVendaDao.NAME_SCHEMA, uniqueConstraints = {
  @UniqueConstraint(name = CartaoVendaDao.NAME_UK_CARTAO_AUTORIZACAO, columnNames = {"autorizacao", "id_cartao"}),
  @UniqueConstraint(name = CartaoVendaDao.NAME_UK_CARTAO_CUPOM, columnNames = {"cupom_num", "id_cartao"}),
  @UniqueConstraint(name = CartaoVendaDao.NAME_UK_CUPOM_DATACUPOM, columnNames = {"cupom_num", "data_cupom"})})
public class CartaoVenda implements Serializable {

  @Id
  @SequenceGenerator(name = CartaoVendaDao.NAME_SEQUENCE, sequenceName = CartaoVendaDao.NAME_SEQUENCE, schema = CartaoVendaDao.NAME_SCHEMA)
  @GeneratedValue(strategy = GenerationType.AUTO, generator = CartaoVendaDao.NAME_SEQUENCE)
  @Column(name = "id")
  private Integer id;
  @ManyToOne
  @JoinColumn(name = "id_cartao", nullable = false)
  @ForeignKey(name = CartaoVendaDao.NAME_FK_CARTAO)
  private Cartao cartao;
  @Index(name = "in_cupom_num")
  @Column(name = "cupom_num")
  private int cupomNum;
  @Index(name = "in_data_cupom")
  @Column(name = "data_cupom", nullable = false)
  @Temporal(TemporalType.DATE)
  private Date dataCupom;
  @Index(name = "in_data_autorizacao")
  @Column(name = "data_autorizacao", nullable = false, updatable = false)
  @Temporal(TemporalType.DATE)
  private Date dataAutorizacao;
  @Index(name = "in_valor_venda")
  @Column(name = "valor_venda", nullable = false)
  private BigDecimal valorVenda;
  @Column(name = "plano", length = 1, updatable = false)
  private String plano;
  @Column(name = "autorizacao", nullable = false, updatable = false)
  private int autorizacao;

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public Cartao getCartao() {
    return cartao;
  }

  public void setCartao(Cartao cartao) {
    this.cartao = cartao;
  }

  public int getCupomNum() {
    return cupomNum;
  }

  public void setCupomNum(int cupomNum) {
    this.cupomNum = cupomNum;
  }

  public Date getDataCupom() {
    return dataCupom;
  }

  public void setDataCupom(Date dataCupom) {
    this.dataCupom = dataCupom;
  }

  public Date getDataAutorizacao() {
    return dataAutorizacao;
  }

  public void setDataAutorizacao(Date dataAutorizacao) {
    this.dataAutorizacao = dataAutorizacao;
  }

  public BigDecimal getValorVenda() {
    return valorVenda;
  }

  public void setValorVenda(BigDecimal valorVenda) {
    this.valorVenda = valorVenda;
  }

  public String getPlano() {
    return plano;
  }

  public void setPlano(String plano) {
    this.plano = plano;
  }

  public int getAutorizacao() {
    return autorizacao;
  }

  public void setAutorizacao(int autorizacao) {
    this.autorizacao = autorizacao;
  }

  @Override
  public int hashCode() {
    int hash = 5;
    hash = 83 * hash + Objects.hashCode(this.id);
    hash = 83 * hash + Objects.hashCode(this.cartao);
    hash = 83 * hash + this.cupomNum;
    hash = 83 * hash + Objects.hashCode(this.dataCupom);
    hash = 83 * hash + Objects.hashCode(this.dataAutorizacao);
    hash = 83 * hash + Objects.hashCode(this.valorVenda);
    hash = 83 * hash + Objects.hashCode(this.plano);
    hash = 83 * hash + this.autorizacao;
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final CartaoVenda other = (CartaoVenda) obj;
    if (!Objects.equals(this.id, other.id)) {
      return false;
    }
    if (!Objects.equals(this.cartao, other.cartao)) {
      return false;
    }
    if (this.cupomNum != other.cupomNum) {
      return false;
    }
    if (!Objects.equals(this.dataCupom, other.dataCupom)) {
      return false;
    }
    if (!Objects.equals(this.dataAutorizacao, other.dataAutorizacao)) {
      return false;
    }
    if (!Objects.equals(this.valorVenda, other.valorVenda)) {
      return false;
    }
    if (!Objects.equals(this.plano, other.plano)) {
      return false;
    }
    if (this.autorizacao != other.autorizacao) {
      return false;
    }
    return true;
  }
}
